import pygame
import random
pygame.mixer.init()
size = width, height = 1000,600

class Enemy(pygame.sprite.Sprite):
    music_boom = pygame.mixer.Sound("./music/enemyboom.wav")
    def __init__(self,position):
        super(Enemy,self).__init__()
        self.speed = 2
        self.index = 0#第一张图片
        self.imagegroup = [pygame.image.load("./pic/pic1/enemy{}.png".format(i)) for i in range(1,11)]
        self.image = self.imagegroup[0]
        self.rect = self.image.get_rect()
        self.rect.x = position[0]
        self.rect.y = position[1]
    # 水平x向右移动
    def update(self, *args):
        self.rect.x -= self.speed
        self.image = self.imagegroup[self.index % 10]
        self.index += 1
        # 用于将自己归于初始位置
        if self.rect.x < 0 - self.rect.width:
            self.rect.x = random.randrange(width,width+1)
            self.rect.y = random.randrange(10,height-50)
    @classmethod
    def musicb(cls):
        cls.music_boom.play()
